package com.tzbank.back.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tzbank.back.service.AuthModuleService;
import com.tzbank.entity.backstage.AuthModule;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
public class AuthModuleController {

	@Autowired
	private AuthModuleService authModuleService;

	/**
	 * 添加权限模块关联关系
	 * @param request
	 * @param authModule
	 * @return Map<String, Object>
	 * @author XUZONGTIAN 2018年5月31日
	 */
	@PostMapping(value = "insertAuthModule")
	public Map<String, Object> insertAuthModule(HttpServletRequest request, @RequestBody AuthModule authModule) {
		try {
			return this.authModuleService.insertAuthModule(authModule);
		} catch (Exception e) {
			log.error("AuthModuleController insertAuthModule error:", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	/**
	 * 删除权限模块关联关系
	 * @param request
	 * @param authModule
	 * @return Map<String, Object>
	 * @author XUZONGTIAN 2018年5月31日
	 */
	@PostMapping(value = "deleteAuthModule")
	public Map<String, Object> deleteAuthModule(HttpServletRequest request, @RequestBody AuthModule authModule) {
		try {
			return this.authModuleService.deleteAuthModule(authModule);
		} catch (Exception e) {
			log.error("AuthModuleController deleteAuthModule error:", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	/**
	 * 修改权限模块关联关系
	 * @param request
	 * @param authModule
	 * @return Map<String, Object>
	 * @author XUZONGTIAN 2018年5月31日
	 */
	@PostMapping(value = "updateAuthModule")
	public Map<String, Object> updateAuthModule(HttpServletRequest request, @RequestBody AuthModule authModule) {
		try {
			return this.authModuleService.updateAuthModule(authModule);
		} catch (Exception e) {
			log.error("AuthModuleController updateAuthModule error:", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	/**
	 * 通过自增主键查询权限模块关联关系
	 * @param request
	 * @param autoId
	 * @return Map<String, Object>
	 * @author XUZONGTIAN 2018年5月31日
	 */
	@GetMapping(value = "selectAuthModuleByAutoId")
	public Map<String, Object> selectAuthModuleByAutoId(HttpServletRequest request,
			@RequestParam(required = true) Integer autoId) {
		try {
			return this.authModuleService.selectAuthModuleByAutoId(autoId);
		} catch (Exception e) {
			log.error("AuthModuleController selectAuthModuleByAutoId error:", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

	/**
	 * 查询权限模块关联关系
	 * @param request
	 * @return Map<String, Object>
	 * @author XUZONGTIAN 2018年5月31日
	 */
	@GetMapping(value = "selectAuthModule")
	public Map<String, Object> selectAuthModule(HttpServletRequest request) {
		try {
			return this.authModuleService.selectAuthModule();
		} catch (Exception e) {
			log.error("AuthModuleController selectselectAuthModule error:", e);
			return ResultUtil.resultMap(CodeUtil.CODE_500.getName(), CodeUtil.CODE_500.getCode(), null);
		}
	}

}
